<template>
   <div class="loginbody">
    <div class="login">
      <div class="login_box" align="center">
        <h3>登录</h3>
        <el-form
          :model="user"
          :rules="loginRules"
          ref="user"
          label-width="0px"
        >
          <el-form-item
            label=""
            prop="userName"
            style="margin-top:10px;"
          >
            <el-row>
              <el-col :span='2'>
                <span class="el-icon-s-custom"></span>
              </el-col>
              <el-col :span='22'>
                <el-input 
                  class="inps"
                  placeholder='账号'
                  v-model="user.userName">
                </el-input>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item
            label=""
            prop="password"
          >
            <el-row>
              <el-col :span='2'>
                <span class="el-icon-lock"></span>
              </el-col>
              <el-col :span='22'>
                <el-input
                  class="inps"
                  type="password"
                  placeholder='密码'
                  v-model="user.password"
                ></el-input>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item style="margin-top:30px;">
            <el-button
              type="primary"
              round
              style="width:120px;"
              class="submit"
              @click="login"
            >登录
            </el-button>
            <el-button
              type="primary"
              round
              style="width:120px;"
              class="submit"
              @click="register"
            >注册
            </el-button>
            <router-link to="/forget" style="color:rgb(139, 128, 128);">已有账号？忘记密码</router-link>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
 
  export default {
    name: "login",
    data: function () {
      return {
        user: {
          userName: '',
          password: ''
        },
        loginRules: {
          userName: [
            {required: true, message: "请输入账号", trigger: "blur"}
          ],
          password: [{required: true, message: "请输入密码", trigger: "blur"}]
        }
      }
    },
   
    methods: {
       login() {
      this.$axios.post("/api/user/login", this.user).then(
        // 返回值
        (res) => {
          console.log(res);
          if (res.data.code==1) {
            sessionStorage.setItem('mytoken',res.data.data[0].name);
            sessionStorage.setItem('sex',res.data.data[0].sex);
            window.location.href = "http://localhost:8081/home#/home";
            
          } else {
            alert("账号或密码错误！");
          }
        }
      );
    },
    register(){
      window.location.href="http://localhost:8081/home#/register"
    }
    }
  }
</script>

<style>
.loginbody {
    overflow: scroll;
    overflow-y: hidden;
    overflow-x: hidden;
  }
 
  .login {
    width: 100%;
    height: 100vh;
    font-size: 19px;
    background-position: left top;
    color: whitesmoke;
    position: relative;
    background-image: url('../assets/imgs/12.jpg');
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }
 
  .login_box {
    width: 260px;
    height: 290px;
    position: absolute;
    top: 0;
    left: 60%;
    right: 0;
    bottom: 0;
    margin: auto;
    padding: 40px 40px 40px 40px;
    box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7);
    opacity: 1;

    background: linear-gradient(
      230deg,
      rgba(53, 57, 74, 0) 0%,
      rgb(0, 0, 0) 100%
    );
  }
 
  .inps input {
    border: none;
    color: #fff;
    background-color: transparent;
    font-size: 12px;
  }
 
  .submit {
    width: 200px;
  }
#link{
  font-family:"Helvetica Neue";
  color:rgb(151, 144, 144);
}
</style>